If you frequently modify generated C++ code outside RSARTE it can be convenient to automate the process of performing code-to-model synchronization, to propagate the changes made in generated code back to the model. RSARTE provides an Ant task that allows such automation to be easily implemented.

The Ant task is called com.ibm.xtools.umldt.rt.transform.cpp.codeSync and here is a simple Ant file that shows how it can be invoked:

<project name="CodeToModelSynch" default="synch">

  <target name="synch">

<com.ibm.xtools.umldt.rt.transform.cpp.codeSync

  transformConfig="/MyProject/HelloWorld.tc"    

    />

  </target>

</project>

Important! If you run this Ant task within RSARTE make sure to unmark the "Build before launch" checkbox in the launch configuration.

If you don't unmark it, the project that contains the Ant file will be built before launching it, which means that the active transformation configuration will be run. This in turn causes all your changes to be overwritten, before the Ant task gets a chance to synchronize them back to the model.

The Ant task supports the following attributes:

[projects]

MyProject1=C:\workspaces\runtime-rteOxygen\MyProject1

MyProject2=C:\workspaces\runtime-rteOxygen\MyProject2

[sources]

D:\generated\folder1

D:\generated\folder2\MyFile.cpp

You can use Java system properties or environment variables in the map file using the syntax ${VAR} or $(VAR).

Note that the model compiler has a command-line option --syncMap which can be used to generate a map file automatically during code generation.

 

All attributes are optional but one of transformConfig or mapFile must be set (but not both at the same time).

 

If you run the code-to-model synchronization Ant task outside of RSARTE, make sure to use the org.eclipse.ant.ui.antRunner application. The command-line should be like this:

<RSARTE> -nosplash -application org.eclipse.ant.ui.antRunner -data <WORKSPACE>

-buildfile <ANT BUILD FILE> <ANT TARGET>

 

<ANT BUILD FILE> is the Ant build file to run.

<ANT TARGET> is the name of a target within the Ant build file to run.

 

If you use a map file that specifies projects to import, the workspace can be empty. Otherwise it should contain the projects with the models that correspond to source files that are synchronized.

Here is an example of an Ant file that specifies a map file:

<project name="CodeToModelSynch" default="synch">

  <target name="synch">

<com.ibm.xtools.umldt.rt.transform.cpp.codeSync

  mapFile="C:\temp\cm_synch.map"    

    />

  </target>

</project>

 

Here is an example of a Windows command-line for calling it from batch:

C:\rsarte-oxygen\eclipse\eclipse.exe -nosplash -application org.eclipse.ant.ui.antRunner -data C:\Users\Mattias\empty-workspace -buildfile C:\temp\cm_synch.ant synch